package util;


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;

/**
 * @ClassName: CreateHtmlUtils  
 * @Description: Java ����ģ�崴�� html
 * @author 
 * @date 2016��4��22�� ����3:51:16
 */
public class CreateHtmlUtils {
    
    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("http://localhost:8080/Tourism/upload/template.html");  
        String imagePath ="http://localhost:8080/Tourism/upload/1234.jpg";
        String disrPath = "C:\\javawebclassfor2018\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\Tourism\\upload";
        String fileName = "liurenw1222";
        MakeHtml(url,imagePath,disrPath,fileName);
    }
    /**
     * @Title: MakeHtml 
     * @Description: ����html
     * @param    filePath �趨ģ���ļ�
     * @param    imagePath ��Ҫ��ʾͼƬ��·��
     * @param    disrPath  ����html�Ĵ��·��
     * @param    fileName  ����html���� 
     * @return void    �������� 
     * @throws
     */
    public static void MakeHtml(URL url,String imagePath,String disrPath,String fileName){
        try {
            String title = "<image src="+'"'+imagePath+'"'+"/>";
            String title1 = "<p>hhhhhhhh<p>";
            String templateContent = "";
        
            BufferedInputStream fileinputstream = new BufferedInputStream(url.openStream());  
           
           // FileInputStream in = new FileInputStream("C:\\javawebclassfor2018\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\Tourism\\upload\\template.html");
          //  BufferedReader fileinputstream = new BufferedReader(new InputStreamReader(in,"UTF-8"));
            
           // BufferedReader fileinputstream = new BufferedReader( new InputStreamReader( new FileInputStream(sava+"/template.html"), "UTF-8") );  
           // FileInputStream fileinputstream = new FileInputStream(filePath);// ��ȡģ���ļ�
            int lenght = fileinputstream.available();
            byte bytes[] = new byte[lenght];
            fileinputstream.read(bytes);
            fileinputstream.close();
            templateContent = new String(bytes);
            System.out.print(templateContent);
            templateContent = templateContent.replaceAll("###title###", title);
            templateContent = templateContent.replaceAll("###title1###", title1);
         //   System.out.print(templateContent);
            
           
       
            
            String fileame = fileName + ".jsp";
            fileame = disrPath+"//" + fileame;// ���ɵ�html�ļ�����·����
            FileOutputStream fileoutputstream = new FileOutputStream(fileame);// �����ļ������
          
            System.out.print(fileame);
      //      byte tag_bytes[] = templateContent.getBytes();
     //       fileoutputstream.write(tag_bytes);
      //      fileoutputstream.close();
            
            OutputStreamWriter oStreamWriter = new OutputStreamWriter(new FileOutputStream(fileame), "utf-8");
            oStreamWriter.append(templateContent);
            oStreamWriter.close();
     
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
    
    
}